﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/BaseMaster/Pages.Master" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="Liu_Project.Web.Admin.Pages.Personal.EntRole.Index" %>

<asp:Content ID="Content1" ContentPlaceHolderID="baseTitle" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="baseHead" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="baseContent" runat="server">
    <div class="layui-row">
        <div class="layui-col-md12">
            <div class="layui-card">
                <%--<div class="layui-card-header"></div>--%>
                <div class="layui-card-body">
                    <table id="tableGrid" lay-filter="tbGrid" class="table_margin_0"></table>
                </div>
            </div>
        </div>
    </div>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="baseScript" runat="server">
    <script>
        ; !function () {
            var tableOption = {
                elem: '#tableGrid',
                url: bootPATH + '/Admin/Handler/Personal/EntRoleHand.ashx',
                where: { act: "LoadPage" },
                height: 'full-40',//表格容器距离浏览器顶部和底部的距离“和”，加上面板上下内边距40px
                cols: [[
                    //{ type: 'checkbox', fixed: true },
                    {
                        fixed: true, title: '<input type="checkbox" name="layTableCheckbox" lay-skin="primary" lay-filter="layTableAllChoose">', width: 48, templet: '<div><input type="checkbox" lay-skin="primary" name="layTableCheckbox"></div>'
                    },
                    { type: 'numbers', title: '序号', fixed: true },
                    { field: 'RoleName', title: '角色名称', minWidth: 120, sort: true },
                    { field: 'CreateTime', title: '创建时间', minWidth: 160, sort: true, templet: '#txtCreateTime' },
                    { field: 'CreateUserName', title: '创建人', minWidth: 120, sort: true, templet: '#txtCreateUserName' },
                    { field: 'UpdateTime', title: '最后修改时间', minWidth: 160, sort: true, templet: '#txtUpdateTime' },
                    { field: 'UpdateUserName', title: '最后修改人', minWidth: 120, sort: true, templet: '#txtUpdateUserName' }
                ]],
            };

            table_render(tableOption);//加载表格数据

            layui.table.on('toolbar(tbGrid)', function (obj) {
                var checkData = layui.table.checkStatus(obj.config.id);
                if ((obj.event != "Add") && checkData.data.length == 0) {
                    top.layer.msg('请选择数据,再操作!', function () { });
                    return;
                }
                switch (obj.event) {
                    case 'Add':
                        {
                            layer.open({
                                type: 1,
                                id: 0,
                                title: "新增角色",
                                content: '<input type="text" id="RoleName" placeholder="请输入角色名称" lay-verify="required" lay-vertype="tips" autocomplete="off" class="layui-input" maxlength="18" />',
                                area: ['300px', '140px'],
                                btn: ['保存', '关闭'],
                                success: function (layero, index) {
                                    layer.setTop(layero);

                                }, yes: function (index, layero) {
                                    var roleName = $("#RoleName").val();
                                    if (StringIsNullOrEmpty(roleName)) {
                                        top.layer.msg("角色名称不能为空");
                                        return false;
                                    }

                                    top.layer.load(1);
                                    GetObjectInfoFunction_Async("Admin/Handler/Personal/EntRoleHand.ashx", {
                                        "act": "Save", "_state": "Add", "RoleName": roleName
                                    }, function (result) {
                                        layer.close(index);
                                        top.layer.msg('保存成功');
                                        layui.table.reload("tableGrid");
                                    })
                                }, btn2: function (index, layero) {
                                    layer.close(index);
                                }
                            });
                        }
                        break;
                    case 'Edit':
                        {
                            layer.open({
                                type: 1,
                                id: 0,
                                title: "编辑角色",
                                content: '<input type="text" id="RoleName" placeholder="请输入角色名称" lay-verify="required" lay-vertype="tips" autocomplete="off" class="layui-input" maxlength="18" value="' + checkData.data[0].RoleName + '" />',
                                area: ['300px', '140px'],
                                btn: ['保存', '关闭'],
                                success: function (layero, index) {
                                    layer.setTop(layero);

                                }, yes: function (index, layero) {
                                    var roleName = $("#RoleName").val();
                                    if (StringIsNullOrEmpty(roleName)) {
                                        top.layer.msg("角色名称不能为空");
                                        return false;
                                    }

                                    top.layer.load(1);
                                    GetObjectInfoFunction_Async("Admin/Handler/Personal/EntRoleHand.ashx", {
                                        "act": "Save", "_state": "Edit", "RoleId": checkData.data[0].RoleId, "RoleName": roleName
                                    }, function (result) {
                                        layer.close(index);
                                        top.layer.msg('保存成功');
                                        layui.table.reload("tableGrid");
                                    })
                                }, btn2: function (index, layero) {
                                    layer.close(index);
                                }
                            });
                        }
                        break;
                    case 'Delete':
                        top.layer.confirm('确定删除吗?', { icon: 3, title: '提示' }, function (index) {
                            let id_Arr = [];
                            for (var i = 0; i < checkData.data.length; i++) {
                                id_Arr.push(checkData.data[i].RoleId);
                            }
                            top.layer.load(1);
                            GetObjectInfoFunction_Async("Admin/Handler/Personal/EntRoleHand.ashx", {
                                "act": "Delete", "Data": id_Arr.toString()
                            }, function (result) {
                                top.layer.close(index);
                                top.layer.msg('删除成功');
                                layui.table.reload("tableGrid");
                            })
                        });
                        break;
                    case 'AuthorizeMenu':
                        {
                            layer.open({
                                type: 2,
                                id: checkData.data[0].RoleId,
                                title: "角色：" + checkData.data[0].RoleName,
                                content: 'AuthorizeMenu.aspx',
                                maxmin: true,
                                area: ['345px', '538px'],
                                btn: ['保存', '取消'],
                                success: function (layero, index) {
                                    var iframeWindow = window['layui-layer-iframe' + index];
                                    iframeWindow.setData("R", checkData.data[0].RoleId);
                                },
                                yes: function (index, layero) {
                                    var iframeWindow = window['layui-layer-iframe' + index];
                                    iframeWindow.Save("R", checkData.data[0].RoleId, index);
                                }
                            });
                        }
                        break;
                    case 'User':
                        {
                            layer.open({
                                type: 2,
                                id: checkData.data[0].RoleId,
                                title: "角色：" + checkData.data[0].RoleName,
                                content: 'RoleUser.aspx',
                                maxmin: true,
                                area: ['90%', '90%'],
                                btn: ['取消'],
                                success: function (layero, index) {
                                    var iframeWindow = window['layui-layer-iframe' + index];
                                    iframeWindow.setData(checkData.data[0].RoleId);
                                }
                            });
                        }
                        break;
                };
            });

        }();
    </script>
</asp:Content>
